﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Catering.Catering_Page.richang
{
    public partial class PeiXunYingJi : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rpt_yingjiqingkuang_Load();
                rpt_peixunxiangmu_Load();
            }

        }

        #region 应急情况
        /// <summary>
        /// 获取应急情况列表
        /// 编写：章建国
        /// </summary>
        private void rpt_yingjiqingkuang_Load()
        {
            string useDate = null;
            string currentClassID = null;
            string currentGroupID = null;
            if (Session["useDate"] != null)
                useDate = Session["useDate"].ToString();
            if (Session["ClassID"] != null)
                currentClassID = Session["ClassID"].ToString();
            if (Session["GroppID"] != null)
                currentGroupID = Session["GroppID"].ToString();
            string ribaobianhao = useDate + "," + currentClassID + "," + currentGroupID + ",";
            Catering_Rules.YingJiQingKuang _yjqkRules = new Catering_Rules.YingJiQingKuang();
            this.rpt_yingjiqingkuang.DataSource = _yjqkRules.GetList(" ribaobianhao = '" + ribaobianhao + "'").Tables[0];
            this.rpt_yingjiqingkuang.DataBind();
        }

        /// <summary>
        /// 新增应急情况
        /// 编写：章建国
        /// </summary>
        /// </summary>
        /// <param name="txt_yjqk_mingchen"></param>
        /// <param name="txt_yjqk_renshu"></param>
        /// <param name="ddl_yjqk_leibie"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static string YingJiQingKuang_Add(string txt_yjqk_mingchen, string txt_yjqk_renshu, string ddl_yjqk_leibie, string _wendang, string _ribaobianhao,string yuan,string jilu,string zongjie)
        {
            string mes = "error";
            Catering_Model.YingJiQingKuang _model = new Catering_Model.YingJiQingKuang();
            Catering_Rules.YingJiQingKuang _yjqkRules = new Catering_Rules.YingJiQingKuang();
            FileUpload fileupload = new FileUpload();

            #region 参数赋值
            _model.mingchen = txt_yjqk_mingchen;
            _model.renshu = !string.IsNullOrEmpty(txt_yjqk_renshu) ? Convert.ToInt32(txt_yjqk_renshu) : 0;
            _model.leibie = ddl_yjqk_leibie;
            if (!string.IsNullOrEmpty(_wendang) && _wendang.Length > 2)
            {
                _model.wendang = _wendang.Substring(1, _wendang.Length - 1);
            }
            _model.yuan = yuan;
            _model.jilu = jilu;
            _model.zongjie = zongjie;
            _model.ribaobianhao = _ribaobianhao;
            #endregion 参数赋值
            if (_yjqkRules.Add(_model) > 0)
            {
                mes = "ok";
            }
            return mes;
        }

        /// <summary>
        /// 编辑应急情况
        /// 编写：章建国
        /// </summary>
        /// <param name="_id"></param>
        /// <param name="txt_yjqk_mingchen"></param>
        /// <param name="txt_yjqk_renshu"></param>
        /// <param name="ddl_yjqk_leibie"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static string YingJiQingKuang_Edit(string _id, string txt_yjqk_mingchen, string txt_yjqk_renshu, string ddl_yjqk_leibie)
        {
            int id = !string.IsNullOrEmpty(_id) ? Convert.ToInt32(_id) : 0;
            if (id <= 0) return "NO";

            Catering_Model.YingJiQingKuang _model = new Catering_Model.YingJiQingKuang();
            Catering_Rules.YingJiQingKuang _yjqkrule = new Catering_Rules.YingJiQingKuang();
            _model = _yjqkrule.GetModel(id);
            _model.leibie = ddl_yjqk_leibie;
            _model.mingchen = txt_yjqk_mingchen;
            _model.renshu = !string.IsNullOrEmpty(txt_yjqk_renshu) ? Convert.ToInt32(txt_yjqk_renshu) : 0;

            _yjqkrule.Update(_model);

            return "OK";
        }

        /// <summary>
        /// 获取单个应急情况
        /// 编写：章建国
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static System.Collections.ArrayList YingJiQingKuang_Get(string _id)
        {
            System.Collections.ArrayList al = new System.Collections.ArrayList();
            Catering_Model.YingJiQingKuang md = new Catering_Rules.YingJiQingKuang().GetModel(Convert.ToInt32(_id));
            al.Add(md.leibie);
            al.Add(md.mingchen);
            al.Add(md.renshu);
            al.Add(md.ribaobianhao);
            al.Add(md.wendang);
            return al;
        }

        /// <summary>
        /// 删除应急情况
        /// 编写：章建国
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void rpt_yingjiqingkuang_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                int delID = Convert.ToInt32(e.CommandArgument);
                if (new Catering_Rules.YingJiQingKuang().Delete(delID))
                {
                    rpt_yingjiqingkuang_Load();
                }
            }
        }
        #endregion 应急情况

        #region 培训项目
        /// <summary>
        /// 获取
        /// 编写：章建国
        /// </summary>
        private void rpt_peixunxiangmu_Load()
        {
            string useDate = null;
            string currentClassID = null;
            string currentGroupID = null;
            if (Session["useDate"] != null)
                useDate = Session["useDate"].ToString();
            if (Session["ClassID"] != null)
                currentClassID = Session["ClassID"].ToString();
            if (Session["GroppID"] != null)
                currentGroupID = Session["GroppID"].ToString();
            string ribaobianhao = useDate + "," + currentClassID + "," + currentGroupID + ",";
            Catering_Rules.PeiXunQingKuang _rules = new Catering_Rules.PeiXunQingKuang();
            this.rpt_peixunqingkuang.DataSource = _rules.GetList(" ribaobianhao = '" + ribaobianhao + "'").Tables[0];
            this.rpt_peixunqingkuang.DataBind();
        }

        /// <summary>
        /// 新增
        /// 编写：章建国
        /// </summary>
        /// </summary>
        /// <param name="txt_yjqk_mingchen"></param>
        /// <param name="txt_yjqk_renshu"></param>
        /// <param name="ddl_yjqk_leibie"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static string PeiXunQingKuang_Add(string txt_pxqk_peixunxiangmu, string txt_pxqk_riqi, string ddl_pxqk_leibie, string hdn_pxqk_filepath, string _ribaobianhao)
        {
            string mes = "error";
            Catering_Model.PeiXunQingKuang _model = new Catering_Model.PeiXunQingKuang();
            Catering_Rules.PeiXunQingKuang _rules = new Catering_Rules.PeiXunQingKuang();
            #region 参数赋值
            _model.peixunxiangmu = txt_pxqk_peixunxiangmu;
            _model.riqi = !string.IsNullOrEmpty(txt_pxqk_riqi) ? Convert.ToDateTime(txt_pxqk_riqi) : DateTime.Now;
            _model.leibie = ddl_pxqk_leibie;

            if (!string.IsNullOrEmpty(hdn_pxqk_filepath) && hdn_pxqk_filepath.Length > 2)
            {
                _model.wendang = hdn_pxqk_filepath.Substring(1, hdn_pxqk_filepath.Length-1);
            }
            
            _model.ribaobianhao = _ribaobianhao;
            #endregion 参数赋值
            if (_rules.Add(_model) > 0)
            {
                mes = "ok";
            }
            return mes;
        }

        /// <summary>
        /// 编辑
        /// 编写：章建国
        /// </summary>
        /// <param name="_id"></param>
        /// <param name="txt_yjqk_mingchen"></param>
        /// <param name="txt_yjqk_renshu"></param>
        /// <param name="ddl_yjqk_leibie"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static string PeiXunQingKuang_Edit(string _id, string txt_pxqk_peixunxiangmu, string txt_pxqk_riqi, string ddl_pxqk_leibie)
        {
            int id = !string.IsNullOrEmpty(_id) ? Convert.ToInt32(_id) : 0;
            if (id <= 0) return "NO";

            Catering_Model.PeiXunQingKuang _model = new Catering_Model.PeiXunQingKuang();
            Catering_Rules.PeiXunQingKuang _pxqkrule = new Catering_Rules.PeiXunQingKuang();

            _model = _pxqkrule.GetModel(id);
            _model.leibie = ddl_pxqk_leibie;
            _model.peixunxiangmu = txt_pxqk_peixunxiangmu;
            _model.riqi = !string.IsNullOrEmpty(txt_pxqk_riqi) ? Convert.ToDateTime(txt_pxqk_riqi) : DateTime.Now;

            _pxqkrule.Update(_model);

            return "OK";
        }

        /// <summary>
        /// 获取单个
        /// 编写：章建国
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static System.Collections.ArrayList PeiXunQingKuang_Get(string _id)
        {
            System.Collections.ArrayList al = new System.Collections.ArrayList();
            Catering_Model.PeiXunQingKuang md = new Catering_Rules.PeiXunQingKuang().GetModel(Convert.ToInt32(_id));
            al.Add(md.leibie);
            al.Add(md.peixunxiangmu);
            al.Add(md.riqi.Value.ToShortDateString());
            al.Add(md.ribaobianhao);
            al.Add(md.wendang);
            return al;
        }

        /// <summary>
        /// 删除
        /// 编写：章建国
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void rpt_peixunqingkuang_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                int delID = Convert.ToInt32(e.CommandArgument);
                if (new Catering_Rules.PeiXunQingKuang().Delete(delID))
                {
                    rpt_yingjiqingkuang_Load();
                }
            }
        }
        #endregion 培训项目

        #region 转换文件
        public string formatfilename(string filenames)
        {
            if (!string.IsNullOrEmpty(filenames))
            {
                var files = filenames.Split(',');
                filenames = "";
                int num = 0;
                foreach (var item in files)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        ++num;
                        filenames += string.Format("<a href='../../UpFile/{0}'>{1}</a>&nbsp;", item, "文件" + num);
                    }
                }
            }
            return filenames;
        }
        #endregion
    }
}